package org.lee.tpl.app;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * NetMall
 * 抽象商城
 *
 * @author dralee
 * @date 2021-11-24 13:41:28
 **/
@Slf4j
public abstract class NetMall {

    /**
     * 登录用户
     */
    private String uid;
    /**
     * 登录密码
     */
    private String password;

    public NetMall(String uid, String password) {
        this.uid = uid;
        this.password = password;
    }

    /**
     * 模拟登录
     *
     * @param uid
     * @param password
     * @return
     */
    protected abstract boolean login(String uid, String password);

    /**
     * 爬虫提取商品信息（登录后的优惠价格）
     *
     * @param skuUrl: 商品链接
     * @return java.util.Map<java.lang.String, java.lang.String>
     * @author dralee
     * @date 2021/11/24 13:45
     **/
    protected abstract Map<String, String> reptile(String skuUrl);

    /**
     * 生成商品海报信息
     *
     * @param goodsInfo
     * @return
     */
    protected abstract String createBase64(Map<String, String> goodsInfo);

    public String generateGoodsPoster(String skuUrl) {
        // 1、验证登录
        if (!login(uid, password)) {
            return null;
        }
        // 2、爬虫商品
        Map<String, String> goodsInfo = reptile(skuUrl);
        // 3、组装海报
        return createBase64(goodsInfo);
    }
}
